﻿using Engine;
using Engine.Graphics;
using Game;
namespace Mekiasm
{
    public class MekItemPipeOut : MachineRotateAbleItem
    {
        public static int Index = 0;
        Model model;
        public BlockMesh blockMesh = new BlockMesh();
        public MekItemPipeOut(string n) : base(n)
        {
            textureSlots = new int[] { 1, 1, 1, 1, 1, 1 };
            model = ContentManager.Get<Model>("Mekiasm/Models/ItemPipe");
            Matrix matrix = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("ItemPipe").ParentBone);
            matrix *= Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f);
            blockMesh.AppendModelMeshPart(model.FindMesh("ItemPipe").MeshParts[0], matrix, false, false, false, false, Color.White);
        }
        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            BlocksManager.DrawMeshBlock(primitivesRenderer, blockMesh, size, ref matrix, environmentData);
        }
        public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
        {
            return true;
        }
        public override MekBlock.DeviceType GetDeviceType()
        {
            return MekBlock.DeviceType.Item;
        }

        public override string GetDescription(int value)
        {
            return base.GetDescription(value);
        }
        public override void GenerateTerrainVertices(Block block, BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
            int direction = ILibrary.GetDirection(value);
            BlockMesh mainMesh = new BlockMesh();
            Matrix matrix = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("ItemPipe").ParentBone);
            matrix *= Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f);
            mainMesh.AppendModelMeshPart(model.FindMesh("ItemPipe").MeshParts[0], matrix, false, false, false, false, Color.White);
            generator.GenerateMeshVertices(block, x, y, z, mainMesh, Color.White, null, geometry.SubsetAlphaTest);
        }
    }
}
